package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.article.ApArticleConfigControllerApi;
import com.usian.article.service.ApArticleConfigService;
import com.usian.model.article.pojos.ApArticleConfig;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article_config")
public class ApArticleConfigController implements ApArticleConfigControllerApi {

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @Override
    @PostMapping("/save")/*保存ap端文章配置表*/
    public ResponseResult saveArticleConfig(@RequestBody ApArticleConfig apArticleConfig) {
        boolean result = apArticleConfigService.save(apArticleConfig);
        if (result){
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }

    @Override
    @GetMapping("/findConfigById/{id}")/*根据id查询app端文章配置*/
    public ApArticleConfig findConfigById(@PathVariable Long id) {
        ApArticleConfig config = apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, id));
        return config;
    }
}
